package com.wms.interceptor;

import com.wms.utils.JwtUtils;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

@Component
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token = request.getHeader("token");
        if (token == null || !JwtUtils.user(token)) {
            response.setStatus(401);
            System.out.println("被拦截了蠢货！快把这个该死的拦截器关了！");
            return false;
        }
        return true;
    }
}
